package cn.uce.cc.rest.control;

import cn.uce.base.exception.DuplicateKeyException;
import cn.uce.cc.api.service.biz.ICcAgentBiz;
import cn.uce.cc.entity.CcAgent;
import cn.uce.web.common.base.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

/**
 * CsSmOrderTypeController:工单类型表。 <br />
 * controller 层 <br />
 * Date: 2016年12月2日 上午10:03:54 <br />
 * @author you
 * @since V1.0.0
 */
@Controller
@RequestMapping("/CsUserController")
public class CsUserController extends BaseController {

    @Resource
    private ICcAgentBiz ccAgentBiz;
    /**
     * 列表页
     * @return
     */
    @RequestMapping("/view")
    public String view(){
        return "authorg/ccUser";
    }


    /**
     * 新增
     * @return
     */
    @RequestMapping("/save")
    @ResponseBody
    public Map<String, Object> save(CcAgent ccAgent, String isExistence){
        int num = 0;
        try {
            if(null != isExistence && ("").equals(isExistence)){
                //如果为空则是新增
                num = ccAgentBiz.save(ccAgent);
            }else{
                //否则是更新
                num = ccAgentBiz.updateByCode(ccAgent);
            }
        } catch (DuplicateKeyException e) {
            return  this.returnError(e.getMessage());
        }
        return this.returnSuccess(num);
    }

    /**
     * 获取详细信息
     * @param empCode
     * @return
     */
    @RequestMapping("/findByCode")
    @ResponseBody
    public Map<String, Object> findByCode(String empCode){
        if(null != empCode && !("").equals(empCode)){
            CcAgent ccAgent = ccAgentBiz.getCcAgentByUserId(empCode);
            if(null != ccAgent){
                return this.returnSuccess(ccAgent);
            }else {
                return this.returnSuccess(0);
            }
        }else{
            return this.returnSuccess(0);
        }
    }
}
